package kr.co.happenstance;

import kr.co.happenstance.lib.NoticeLib;
import kr.co.happenstance.lib.vo.LibResultVo;
import kr.co.happenstance.lib.vo.NoticeInfoResultVo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class NoticeDetailActivity extends BaseActivity implements View.OnClickListener{
	protected final String TAG = "<<<NoticeDetailActivity>>>";
	
	private int seq;
	private TextView tvTitle;
	private TextView tvContents;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_notice_detail);
		
		tvTitle = (TextView) this.findViewById(R.id.tv_title);
		tvContents = (TextView)this.findViewById(R.id.tv_contents);
		tvContents.setMovementMethod(new ScrollingMovementMethod());
		
		seq = this.getIntent().getExtras().getInt("seq");
		Log.d(TAG, "seq["+seq+"]");
		
		new NoticeDetailTask().execute();
		addActivity(this);
	}	
	
	@Override
	public void onClick(View v) {
		switch(v.getId()){
			case R.id.btn_pop_close:
			case R.id.btn_ok:	
				Log.d(TAG, "btn_pop_close onClick.....");
				finish();
				break;
		}		
		
	}
	
	private class NoticeDetailTask extends AsyncTask<Void, Void, LibResultVo> {
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgress();
		}	
		
		@Override
		protected LibResultVo doInBackground(Void... arg0) {
			LibResultVo vo = null;
			try{
				NoticeLib lib = new NoticeLib();
				vo = lib.info(seq);
				
			}catch(Exception e){
				e.printStackTrace();
			}
			return vo;
		}
		
		@Override
		protected void onPostExecute(LibResultVo resultVo) {
			closeProgress();
			
			NoticeInfoResultVo vo = (NoticeInfoResultVo) resultVo;
			if(vo == null || vo.getResult().equals(C.API_RESULT_VALUE_FAIL)){
				Log.d(TAG, "NoticeListResultVo null......");
				new CustomAlertDialogBuilder(NoticeDetailActivity.this, R.string.alert_title, R.string.alert_msg_exception).create();
			}else{
				tvTitle.setText(vo.getNoticeInfo().title);
				tvContents.setText(vo.getNoticeInfo().contents);
			}
			
		}	
		
	}	
	

}
